/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package logging;

import AccessLayer.AccessLayer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Properties;
import logging.LogLevel.Level;

/**
 *
 * @author Marco
 */
public class AppendManager {

    private static HashMap<String, Level> levelMap = new HashMap<String, Level>();
    private static ArrayList<IAppender> appenderList = new ArrayList<IAppender>();


    public static void configure() {
        Properties p = AccessLayer.giveConfig();
        appenderList.add(new FileAppender());
        levelMap.put("FileLogLevel", Level.valueOf(p.getProperty("FileLogLevel")));

        appenderList.add(new ConsoleAppender());
        levelMap.put("ConsoleLogLevel", Level.valueOf(p.getProperty("ConsoleLogLevel")));

        GuiAppender gui = new GuiAppender();
        gui.configure();
        appenderList.add(gui);
        levelMap.put("GuiLogLevel", Level.valueOf(p.getProperty("GuiLogLevel")));

    }

    public static void write(Level level, String msg, Exception ex) {
        for (IAppender i : appenderList) {
            if (levelMap.get(i.toString()).ordinal() <= level.ordinal()) {
                i.write(level, msg, ex);
            }
        }
    }

    public static void write(Level level, String msg) {
        for (IAppender i : appenderList) {
            if (levelMap.get(i.toString()).compareTo(level) <= 0) {
                i.write(level, msg);
            }
        }
    }

}
